import { ChunkEntityType, ChunkEntityUpdateType, ColliderType, ColliderUpdateType, CollisionGroup, EntityTag } from "../../GameDef";
import { CircleShape } from "../../lib/kgame/d2/shape/CircleShape";
import { ECSScene } from "../../lib/kgame/ecs/ECSScene";
import { IVec2 } from "../../lib/kgame/util/Defined";
import { ChunkEntityCmp } from "../cmp/ChunkEntityCmp";
import { ColliderCmp } from "../cmp/ColliderCmp";
import { FoodCmp } from "../cmp/FoodCmp";

/**
 * 食物工厂
 */
export class FoodFactory {

    /**
     * 创建食物
     * @param scene 场景
     * @param pos 位置
     * @param score 分数
     * @param lifeTime 存活时间 -1 永久存活
     * @param color 十进制颜色 没有代表随机
     */
    static createFood(scene: ECSScene, pos: IVec2, score: number, lifeTime?: number, color?: number) {
        const entity = scene.createEntity();
        entity.tag = EntityTag.food;
        entity.pos.setPosTo(pos);
        const collider = entity.addCmp(ColliderCmp<CircleShape>);
        collider.onCreate(new CircleShape(0), ColliderType.food, CollisionGroup.none, entity.id, ColliderUpdateType.static);
        const food = entity.addCmp(FoodCmp).onCreate(score, collider, lifeTime, color);
        entity.addCmp(ChunkEntityCmp).onCreate(ChunkEntityType.food, ChunkEntityUpdateType.static, collider.shape.worldAABB);
        return food;
    }

}